package com.monogo;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;

public class Monogo {
	

	private String path = "db/";
	private String path_ = path.replace("/", "");
	private String SuffixName = ".xml";
	public List<String> findDataBase() {

		File file = new File(path_);
		if (file.exists() && file.isDirectory()) {
			List<String> fileName = new ArrayList<String>();

			for (String name : file.list()) {
				if (name.indexOf(SuffixName) > 0) {
					fileName.add(name.substring(0, name.lastIndexOf(SuffixName)));
				}

			}
			return fileName.size() > 0 ? fileName : null;
		}

		return null;
	}

	public void createDataBase(String dataBaseName) {
		try {
			FileOutputStream fiel = new FileOutputStream(path + dataBaseName + SuffixName);
			Document document = new Document();
			Element root = new Element("database");
			Element table = new Element("tables");
			root.addContent(table);
			document.setRootElement(root);
			XMLOutputter out = new XMLOutputter();
			out.output(document, fiel);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public boolean deleteDataBase(String dataBaseName) {

		try {
			File file = new File(path + dataBaseName + SuffixName);
			if (file.exists()) {
				file.delete();
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}

}
